package com.kayak.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class JdbcConnection {
private static Connection getConn() {
		
		PropertiesUtils.loadFile("jdbc.properties");

		String url = PropertiesUtils.getPropertyValue("url");  
        String username = PropertiesUtils.getPropertyValue("username");  
        String password = PropertiesUtils.getPropertyValue("password");    
        String driver = PropertiesUtils.getPropertyValue("driver");    
	    Connection conn = null;
	    try {
	    	//classLoader,加载对应驱动
	        Class.forName(driver); 
	        conn = (Connection) DriverManager.getConnection(url, username, password);
	    } catch (ClassNotFoundException e) {
	        e.printStackTrace();
	    } catch (SQLException e) {
	        e.printStackTrace();
	    }
	    return conn;
	}
	
	public static void  creactSql(String getSql) {
	    Connection conn = getConn();
	   
	    String sql = getSql;
	   // PreparedStatement pstmt;
	    Statement  stmt = null;
	    try {
	    	//stmt = (PreparedStatement) conn.prepareStatement(sql);
	    	stmt = conn.createStatement();
	    	stmt.executeUpdate(sql);
	    	stmt.close();
	        conn.close();
	    } catch (SQLException e) {
	        e.printStackTrace();
	    }
	    
	}
}
